package cn.ceplc.nlu.admin.service.impl;

import cn.ceplc.nlu.admin.domain.User;
import cn.ceplc.nlu.admin.util.PasswordUtils;
import cn.ceplc.nlu.base.service.impl.BaseServiceImpl;
import cn.ceplc.nlu.admin.repository.UserRepository;
import cn.ceplc.nlu.admin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends BaseServiceImpl<User, Long> implements UserService {


    private final UserRepository userRepository;

    @Autowired
    public UserServiceImpl(UserRepository userRepository) {
        this.baseRepository = userRepository;
        this.userRepository = userRepository;
    }

    @Override
    public User findByUserName(String username) {
        return userRepository.findByUsername(username);
    }

    @Override
    public User insert(User entity) {
        entity.setPassword(PasswordUtils.encode(entity.getPassword(), entity.getSalt()));
        return userRepository.save(entity);
    }
}
